<?php
/**
 *  
 * Форма регистрации пользователя
 * 
 * @author
 */



class User_Form_User extends Zen_Form {
	/**
	 * Создание формы
	 */
	public function init() {
		// Вызываем родительский метод
		parent::init ();
		$this->setMethod ( 'POST' );
		
		
		$name = new Zend_Form_Element_Text ('name', array ('class' => 'zend_text' ) );
		$name->setLabel ( "Имя" )->setRequired ( true )->setFilters ( array ('StringTrim', 'StripTags' ) );
		
        $login = new Zend_Form_Element_Text ( 'login', array ('class' => 'zend_text' ) );
		$login->setLabel ( "Имя пользователя (логин): " )->setRequired ( true )->setFilters ( array ('StringTrim', 'StripTags' ) );		
		$login->addValidator ('NoDbRecordExists',true, array ('user', 'login' ));
		
		$email = new Zend_Form_Element_Text ( 'email', array ('class' => 'zend_text' ) );
		$email->setLabel ( "Email: " )->setRequired ( true )->addValidator ( 'EmailAddress' )->setFilters ( array ('StringTrim', 'StripTags' ) );
		$email->addValidator ('NoDbRecordExists',true, array ('user', 'email' ));
		
		
		
		$pass = new Zend_Form_Element_Password ( 'pass', array ('class' => 'zend_text','autocomplete' => "off"	 ) );
		$pass->setLabel ( "Пароль " )->setRequired ( false )->setFilters ( array ('StringTrim', 'StripTags' ) );
		$pass->setValidators ( array (array ('StringLength', true, array (6, 400, 'utf-8' ) ) ) );
		$pass->setDescription ( 'Длина пароля не менее 6 символов');
	
		$role=new Zend_Form_Element_Select('role', array ('class' => 'zend_select','label'=>'Роль','required'=>true));
		
		$role_list=new Zen_List('user_role');
		$roles=$role_list->select()->setColumns(array('alias','label'))->getData();
		$data=array();
		foreach($roles as $r){
			$data[$r['alias']]=$r['label'];
		}
		
		
		$role->setMultiOptions($data);
		
		
		$confirm_password = new Zend_Form_Element_Password ( '_confirm_approve', array ('required' => false, 'label' => 'Подтвердите пароль ', 'maxlength' => '30', 'class' => 'zend_text', 'validators' => array (array ('EqualInputs', true, array ('pass' ) ) ) ) );
		
		
		$submit = new Zend_Form_Element_Submit ( 'submit', array ('label' => 'Сохранить' ) );
		$this->addElements ( array (
		 	$name,
		    $login,
		    $role,
		    $pass,
		    $confirm_password,
		    $email,$submit ) );
	}
}